<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
 <TITLE>SDCC Compiler User Guide: Compiling.</TITLE>
 <LINK HREF="SDCCUdoc-4.html" REL=next>
 <LINK HREF="SDCCUdoc-2.html" REL=previous>
 <LINK HREF="SDCCUdoc.html#toc3" REL=contents>
</HEAD>
<BODY>
<A HREF="SDCCUdoc-4.html">Next</A>
<A HREF="SDCCUdoc-2.html">Previous</A>
<A HREF="SDCCUdoc.html#toc3">Contents</A>
<HR>
<H2><A NAME="Compiling"></A> <A NAME="s3">3. Compiling.</A> </H2>

<H2><A NAME="One Source File"></A> <A NAME="ss3.1">3.1 Single Source file projects.</A>
 </H2>

<P>For single source file projects the process is very simple. Compile your
programs with the following command
<P>
<PRE>
sdcc sourcefile.c
 
</PRE>
<P>The above command will compile ,assemble and link your source file. Output
files are as follows.
<P>
<UL>
<LI>sourcefile.asm - Assembler source file created by the compiler</LI>
<LI>sourcefile.lst - Assembler listing file created by the Assembler</LI>
<LI>sourcefile.rst - Assembler listing file updated with linkedit information
, created by linkage editor</LI>
<LI>sourcefile.sym - symbol listing for the sourcefile, created by the assembler.</LI>
<LI>sourcefile.rel - Object file created by the assembler, input to Linkage
editor.</LI>
<LI>sourcefile.map - The memory map for the load module, created by the Linker.</LI>
<LI>sourcefile.&lt;ihx | s19&gt; - The load module : ihx - Intel hex format
(default ), s19 - Motorola S19 format when compiler option --out-fmt-s19 is
used.</LI>
</UL>
<H2><A NAME="ss3.2">3.2 Projects with multiple source files.</A>
 </H2>

<P>SDCC can compile only ONE file at a time. Let us for example assume that
you have a project containing the following files.
<P>
<PRE>
foo1.c ( contains some functions )foo2.c (contains some more functions)foomain.c (contains more functions and the function main)
 
</PRE>
<P>The first two files will need to be compiled separately with the commands
<P>
<PRE>
sdcc -c foo1.csdcc -c foo2.c
 
</PRE>
<P>Then compile the source file containing main and link the other files together
with the following command.
<P>
<PRE>
sdcc foomain.c foo1.rel foo2.rel
 
</PRE>
<P>Alternatively foomain.c can be separately compiled as well
<P>
<PRE>
sdcc -c foomain.c sdcc foomain.rel foo1.rel foo2.rel
 
</PRE>
<P>The file containing the main function MUST be the FIRST file specified
in the command line , since the linkage editor processes file in the order
they are presented to it.
<H2><A NAME="ss3.3">3.3 Projects with additional libraries.</A>
 </H2>

<P>Some reusable routines may be compiled into a library, see the documentation
for the assembler and linkage editor in the directory SDCCDIR/asxxxx/asxhtm.htm
this describes how to create a .lib library file, the libraries created in
this manner may be included using the command line, make sure you include the
-L &lt;library-path&gt; option to tell the linker where to look for these files.
Here is an example, assuming you have the source file 'foomain.c' and a library
'foolib.lib' in the directory 'mylib'.
<P>
<PRE>
sdcc foomain.c foolib.lib -L mylib
 
</PRE>
<P>Note here that 'mylib' must be an absolute path name.
<P>The view of the way the linkage editor processes the library files, it
is recommended that you put each source routine in a separate file and combine
them using the .lib file. For an example see the standard library file 'libsdcc.lib'
in the directory SDCCDIR/sdcc51lib.
<HR>
<A HREF="SDCCUdoc-4.html">Next</A>
<A HREF="SDCCUdoc-2.html">Previous</A>
<A HREF="SDCCUdoc.html#toc3">Contents</A>
</BODY>
</HTML>
